/* 
 * File:   DAOBatchMerge.h
 * Author: Morpheus
 *
 * Created on 29 juin 2013, 19:48
 */

#ifndef DAOBATCHMERGE_H
#define	DAOBATCHMERGE_H

#include "MyBatchMerge.h"

class QDataStream;

class BatchMergeCriteria {
public:
    BatchMergeCriteria();
    BatchMergeCriteria(const BatchMergeCriteria& orig);
    ~BatchMergeCriteria();
    
    enum TagDateAdv{ None, Since, Before, Beetween };
    enum TagDate{ Date, DateTime, RelativeDate, RelativeDateTime };
    enum SortedTag{ TraitedASC, TraitedDEC, CreatedDateASC, CreatedDateDEC, ModifiedDateASC, ModifiedDateDEC, NameASC, NameDEC };
    void updateDates();
    
    int id;
    QString name;
    Qt::CheckState traited;
    bool alwaysShowNotTraited;
    
    TagDateAdv createdDateTagAdv;
    TagDate createdDateTag;
    QDateTime createdDate1;
    QDateTime createdDate2;
    
    TagDateAdv modifiedDateTagAdv;
    TagDate modifiedDateTag;
    QDateTime modifiedDate1;
    QDateTime modifiedDate2;
    
    qint64 relativeCreatedDate[4];
    qint64 relativeModifiedDate[4];
    
    static const int version;
};

QDataStream& operator<<(QDataStream& , const BatchMergeCriteria&);
QDataStream& operator>>(QDataStream& , BatchMergeCriteria&);

class DAOBatchMerge {
public:
    virtual ~DAOBatchMerge();
    
    static DAOBatchMerge* self();
    
    QList<MyBatchMerge> getBatchMergeByCriteria(const BatchMergeCriteria& criteria, const QVariantList& moreBatchMerge);
    
    MyBatchMerge getBatchMerge(const int& );
    
    void saveBatchMerge(MyBatchMerge& );
    void updateBatchMergeDoWthSucces(const int&, const bool& );
    void removeBatchMerge(const QList<int>& ); // DONE
    
    QList<MyBatchUnit> getBatchUnit(const int& mergeId);
    
    bool batchMergeExist(const int&);
    
    void insertBatchCriteria(BatchMergeCriteria& criteria);
    void updateBatchCriteria(BatchMergeCriteria& criteria);
    void removeBatchCriteria(const int&);
    void setCurrentBatchCriteria(const int&);
    BatchMergeCriteria getBatchCriteria(const int&);
    BatchMergeCriteria getCurrentBatchCriteria();
    QList<BatchMergeCriteria> getAllBatchCriteria();
    
private:
    DAOBatchMerge();
    
    void openDB();
    void createDB();
    void insertBatchMerge(MyBatchMerge&);
    void updateBatchMerge(const MyBatchMerge&);
    // remove old and re-insert
    void updateBatchUnit(const QList<MyBatchUnit>&, const int& mergeId);
    
    static DAOBatchMerge* instance;
    

};

#endif	/* DAOBATCHMERGE_H */

